---
layout: example
categories: example/v1.0.0
version: v1.0.0
title: GeoJSON marker from GitHub
description: Load a marker from a remote location like GitHub
tags:
  - markers
---
<div id='map'></div>

<!-- jQuery is required for this example. -->
<script src='https://code.jquery.com/jquery-1.11.0.min.js'></script>
<script>
var url = 'https://api.github.com/repos/mapbox/mapbox.js/contents/test/manual/example.geojson';

var map = L.mapbox.map('map')
  .setView([0.3941, -78.2227], 7)
  .addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'));

function load() {
  // Fetch just the contents of a .geojson file from GitHub by passing
  // `application/vnd.github.v3.raw` to the Accept header
  // As with any other AJAX request, this technique is subject to the Same Origin Policy:
  // http://en.wikipedia.org/wiki/Same_origin_policy the server delivering the request should support CORS.
  $.ajax({
    headers: {
      'Accept': 'application/vnd.github.v3.raw'
    },
    xhrFields: {
      withCredentials: false
    },
    dataType: 'json',
    url: url,
    success: function(geojson) {
        // On success add fetched data to the map.
        L.mapbox.featureLayer(geojson).addTo(map);
    }
  });
}

$(load);
</script>
